package com.tjn.list_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 陶镓妮
 * @version 1.0
 * 三种遍历方式
 */
public class ListFor {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("孙燕姿");
        list.add("薛之谦");
        list.add("汪苏泷");
        list.add("周杰伦");
        list.add("五月天");

        System.out.println("====普通for循环====");
        //1.普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        System.out.println("====foreach循环====");
        //2.foreach循环
        for (Object obj : list) {
            System.out.println(obj);
        }

        System.out.println("====迭代器====");
        //3.迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }
    }
}
